package com.livegoods.rabbitmq;

import com.livegoods.commons.pojo.LivegoodsPublistMessage;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PublishMessage {

    @Autowired
    private AmqpTemplate amqpTemplate;


    /**
     * 异步发送消息方法
     * @param exchange 交换器  接受消息发送到队列
     * @param routingKey 路由key 绑定交换器和队列
     * @param message 发送消息，任意数据
     */
    public void asyncSenderMessage(String exchange, String routingKey, LivegoodsPublistMessage message){
        amqpTemplate.convertAndSend(exchange,routingKey,message);
    }


    /**
     * 同步发送消息方法
     * @param exchange 交换器  接受消息发送到队列
     * @param routingKey 路由key 绑定交换器和队列
     * @param message 发送消息，任意数据
     */
    public Object syncSenderMessage(String exchange,String routingKey, LivegoodsPublistMessage message){
        Object result = amqpTemplate.convertSendAndReceive(exchange, routingKey, message);
        return result;
    }


}
